<template> 
    <div class="recipe-page">
        <recipe-list @detail-item="detailItem" :item="item" v-for="(item,index) in resDataList" :key="index"></recipe-list> 
        <div class="text-center loadmore" v-if="resDataList.length==0||!resDataList">暂无数据...</div>
    </div> 
</template>

<script>
import recipeList from '@/components/tpl/chufang/recipe-list' 
import * as api from '@/utils/api' 
export default {
    onShow(opt){
        this.getDataList();
    },
    components: { 
        recipeList
    }, 
    data () {
        return {
            resDataList:[],
            offset:0,
            limit:10,
            count:0,  //总条数
        }
    },
    methods:{
        detailItem(item,val){ 
            if(val==1){
                let url = `./../recipe-pay/main?orderId1=${item.id}`;
                wx.navigateTo({url}) 
            }else if(val==2){
                let url = `./../recipe-detail/main?orderId2=${item.id}`;
                wx.navigateTo({url}) 
            }
        },
        getDataList(val){
            let vm =this;
            let body={
                model: "Orders", 
                offset:vm.offset,
                limit:vm.limit,
                with:{
                    "0":"doctor"
                },
                condition:{
                    uid: wx.getStorageSync('u_id') 
                } 
            };
            api.commonSite(body).then(res=>{
                if(res.data.code==200){
                    vm.count=res.data.data.count;
                    let arr=[];
                    res.data.data.data.forEach((item,index)=>{
                        if(item.status==0){
                            item.statusTxt="待审核"
                        }else if(item.status==1){
                            item.statusTxt="待付款"
                        }else if(item.status==2){
                            item.statusTxt="待发货"
                        }else if(item.status==3){
                            item.statusTxt="已发货"
                        }else if(item.status==4){
                            item.statusTxt="已完成"
                        }else  if(item.status==98){
                            item.statusTxt="审核失败"
                        }else if(item.status==99){
                            item.statusTxt="已关闭"
                        }
                        if(item.freight){   
                            item.amount=parseFloat(item.freight)+parseFloat(item.order_price);
                        }else{
                            item.amount= item.order_price;
                        }
                        arr.push(item);   
                    });
                    if(val=='down'){
                        arr.forEach((list,index)=>{
                            vm.resDataList.push(list);
                        }) 
                    }else{
                        vm.resDataList=arr;
                    } 
                }
            });
        },
    },
    // 上拉加载，拉到底部触发
    onReachBottom() {
        this.offset+=this.limit; 
        if(this.count>this.resDataList.length){
            this.getDataList('down');
        } 
    },
}

</script>
 
<style scoped lang="scss">
.recipe-page{
    padding:30rpx;
    box-sizing:border-box;
      .loadmore{
        font-size:28rpx;
        color:#ccc; 
        padding-bottom:40rpx;
    }
} 
</style>
